{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "a5f3e229-264e-49ae-b028-1b6fc3ed39a4",
   "metadata": {},
   "outputs": [],
   "source": [
    "from torch.utils.tensorboard import SummaryWriter\n",
    "import os\n",
    "from PIL import Image\n",
    "import numpy as np\n",
    "import pandas as pd"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "63d001c1-bd47-4727-927d-f8e75fd8086a",
   "metadata": {},
   "outputs": [],
   "source": [
    "writer = SummaryWriter(\"logs\")\n",
    "# writer.add_image()\n",
    "# write.add_scalar()\n",
    "# help(SummaryWriter)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "aefa54b8-afcd-4d15-b882-9835891875fa",
   "metadata": {},
   "outputs": [],
   "source": [
    "image_path = r\"D:\\desktop\\practice\\数据集\\hymenoptera_data\\train\\ants\\0013035.jpg\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "0b908e7a-e11b-4950-8023-42af1dcfbde3",
   "metadata": {},
   "outputs": [],
   "source": [
    "img = Image.open(image_path)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "aae33946-69e2-44d7-84ba-6dfce8a0922a",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "PIL.JpegImagePlugin.JpegImageFile"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "type(img)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "bc9ffcd0-297f-4e2f-b5b2-a4edac1dcaec",
   "metadata": {},
   "outputs": [],
   "source": [
    "img_array = np.array(img)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "b70a462a-5ca1-4631-b2ba-1b1abb6c6e11",
   "metadata": {},
   "outputs": [],
   "source": [
    "writer.add_image(\"ant\",img_array,1,dataformats=\"HWC\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "d1e28892-0107-4874-9a25-73ed3da64c80",
   "metadata": {},
   "outputs": [],
   "source": [
    "writer.close()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "3b3b0cc4-6089-4ec3-b891-215eecdf190f",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
